//保留两位小数
export function returnFloat(value) {
	if (value == undefined||value=='') {
		value = 0;
	}
	var value = Math.round(parseFloat(value) * 100) / 100;
	var xsd = value.toString().split(".");
	if (xsd.length == 1) {
		value = value.toString() + ".00";
		return value;
	}
	if (xsd.length > 1) {
		if (xsd[1].length < 2) {
			value = value.toString() + "0";
		}
		return value;
	}
}

//获取当前年月日
export function getDate(date) {
	var date = new Date(date);
	var nowDate
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	if (month < 10) {
		month = "0" + month;
	}
	if (day < 10) {
		day = "0" + day;
	}
	return nowDate = year + "-" + month + "-" + day;
}

//获取月日
export function shortTime(data){
	if(data){
		return data.substring(5);
		}
	}
//支付
export function reallyBuy(obj,order_id,type){
	uni.requestPayment({ // 调起微信支付
		timeStamp: obj.timeStamp + '',
		nonceStr: obj.nonceStr,
		package: obj.package,
		signType: obj.signType,
		paySign: obj.paySign,
		service: 3,
		success:(res) => {
			uni.showToast({
				title: '支付成功'
			}).then(() => {
				uni.navigateBack();
			})
		},
		fail: (res) => {
			if(type){
				//外卖支付
				uni.navigateBack();
			}else{
				//团购支付
				uni.navigateTo({
					url:"../orderDetail/orderDetail?order_id="+order_id
				})
			}
			if (res.errMsg.indexOf("cancel") > -1) {
				uni.showToast({
					title: '支付取消',
					icon: 'none'
				})
			} else {
				uni.showToast({
					title: '支付失败',
					icon: 'none'
				})
			}
		}
	})
}
